package iedcyt.acute.dataAccess.dao.maauco;

import iedcyt.acute.dataAccess.domain.maauco.Au0;
import iedcyt.acute.dataAccess.domain.maauco.Co0;
import iedcyt.acute.dataAccess.generic.SpringDao;
import iedcyt.acute.dataAccess.idao.maauco.IAupioDao;
import iedcyt.acute.dataAccess.utils.Pair;

import java.util.List;



public class AupioDao extends SpringDao implements IAupioDao  {


	@Override
	public int selectMaxIdno() {
		return _jdbcTemplate.queryForInt("SELECT MAX(IDNO) FROM AUPIO");
	}


	
	@Override
	public List<Pair<Au0, Co0>> selectAll() {
		
		return _jdbcTemplate.query("SELECT AUPIO.IDNO, AU0.NO, CO0.NO, AU0.AUTH, " +
				"CO0.CORP, co0.PROVINCIA, CO0.INSTIT, CO0.ORGANISMO, CO0.DPTO, CO0.ISO " +
				"FROM AUPIO INNER JOIN " +
				"(AU0 INNER JOIN CO0 ON AU0.IDNO = CO0.IDNO AND AUPIO.NUMADD = CO0.NUMADD) " +
				"ON AUPIO.IDNO = AU0.IDNO AND AUPIO.NO = AU0.NO",
				new AupioRowMapper());
	}
	
	@Override
	public List<Pair<Au0, Co0>> selectByIdnoRange(int idno1, int idno2) {
		
		return _jdbcTemplate.query("SELECT AUPIO.IDNO, AU0.NO, CO0.NO, AU0.AUTH, " +
				"CO0.CORP, co0.PROVINCIA, CO0.INSTIT, CO0.ORGANISMO, CO0.DPTO, CO0.ISO " +
				"FROM AUPIO INNER JOIN " +
				"(AU0 INNER JOIN CO0 ON AU0.IDNO = CO0.IDNO) " +
				"ON AUPIO.IDNO = AU0.IDNO AND AUPIO.NO = AU0.NO " +
				"WHERE AUPIO.IDNO >= ? AND AUPIO.IDNO <= ? AND AUPIO.NUMADD = CO0.NUMADD",
				new Object[] { idno1, idno2 },
				new AupioRowMapper());
	}
	
	@Override
	public List<Pair<Au0, Co0>> select(int idno) {
		return _jdbcTemplate.query("SELECT AUPIO.IDNO, AU0.NO, CO0.NO, AU0.AUTH, " +
				"CO0.CORP, co0.PROVINCIA, CO0.INSTIT, CO0.ORGANISMO, CO0.DPTO, CO0.ISO " +
				"FROM AUPIO INNER JOIN " +
				"(AU0 INNER JOIN CO0 ON AU0.IDNO = CO0.IDNO) " +
				"ON AUPIO.IDNO = AU0.IDNO " +
				"WHERE AUPIO.IDNO = ?",
				new Object[] { idno },
				new AupioRowMapper());
	}

}

